<?php

namespace app\index\model;

use think\Model;

class Group extends Model
{
    //查看所有分类信息
    public function sel() {
        $res = self::all();
        return $res;
    }
    public function apiSel() {
        $res = self::column('id,name');
        return $res;
    }
    //新增分类信息
    public function add($name) {
//        $res = db('group')->insert(['name'=>$name]);
//        $class = new self();
//        $class->name = $name;
//        $res = $class->save();
        $res = self::create(['name'=>$name]);
        if($res) {
            return $res;
        }else {
            return false;
        }
    }
    //删除分类
    public function del($id) {
        $class = self::get($id);
        $res = $class->delete();
        if($res) {
            return $res;
        }else {
            return false;
        }
    }
}
